package com.ganzalang.gmall.concurrentart.jvm;

/**
 * @description:
 * @author: Ganzalang
 * @Date 2022/4/18 10:36
 */
public class VolatileTest {
    public static volatile int a = 0;
    private static final int THREADS_COUNT = 10000;

    public static void incr() {
        a++;
    }

    public static void main(String[] args) {
        Thread[] threads = new Thread[THREADS_COUNT];

        for (int i = 0; i < THREADS_COUNT; i++) {
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    incr();
                }
            });
            threads[i].start();
        }

        while (Thread.activeCount() > 1) {
            Thread.yield();
        }

        System.out.println("a");
    }
}
